package com.pheonix.fbupdates;

import java.io.Serializable;

import com.pheonix.events.TimeLineView;

import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class EventsActivity extends FragmentActivity {
	
	private static Uri calendarURI = CalendarContract.Events.CONTENT_URI;;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    TimeLineView tlv = new TimeLineView(this);
	    setContentView(tlv);
	    //populateAllEvents();
	    
		EventFragment event = new EventFragment();
		FrameLayout ll = new FrameLayout(this);
		ll.setId(1123134);
		getSupportFragmentManager().beginTransaction().add(ll.getId(), event).commit();
		tlv.test(ll);
	}
	
	private void populateAllEvents() {
		
		Cursor events = getAllCalendarEvents();

		while(events.moveToNext()) {
			EventFragment event = new EventFragment();

			Bundle arguments = new Bundle();
			arguments.putString("eventTitle", events.getString(events.getColumnIndex(Events.TITLE)));
			arguments.putString("eventLocation", events.getString(events.getColumnIndex(Events.EVENT_LOCATION)));
			arguments.putString("eventTime", events.getString(events.getColumnIndex(Events.DTSTART)));
			event.setArguments(arguments);
			getSupportFragmentManager().beginTransaction().add(R.id.event, event).commit();
		}
	}

	private Cursor getAllCalendarEvents() {

		Cursor events = getContentResolver().query(calendarURI, 
				null, 
				null, 
				null, 
				Events.DTSTART);
		
		return events;
	}
	
}
